package com.jxc.jxc01.grc.web;

import com.jxc.jxc01.grc.entity.Procurement;
import com.jxc.jxc01.grc.entity.RespResult;
import com.jxc.jxc01.grc.service.IProcurementService;
import com.jxc.jxc01.grc.service.impl.ProcurementSreviceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(value = "/obscurePro")
public class ObscureProServlet extends HttpServlet {
    @Override
    protected void service
            (HttpServletRequest request,
             HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        System.out.println("sadfkjhsafja");

        IProcurementService procurementService = new ProcurementSreviceImpl();
        String purchaseId1 = request.getParameter("purchaseId");
        if (purchaseId1 != ""){
            int purchaseId = Integer.parseInt(purchaseId1);
            System.out.println(purchaseId);
            List<Procurement> procurements = procurementService.queryProcurementBynano(purchaseId);
            if (procurements != null && procurements.size() > 0){
                RespResult result = new RespResult();
                result.setCode(0);
                result.setMessage("ok");
                result.setCount(procurements.size());
                result.setData(procurements);
                //创建session
                HttpSession session = request.getSession();
                session.setAttribute("procurements", result);
                response.sendRedirect("caigou.html");
            }
            out.close();
        }else {
            response.sendRedirect("caigou.html");
        }
    }
}
